﻿///////////////////////////////////////
//////add by yl 2014年8月21日16:22:21
//////主要功能:处理班组设备报修
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// Contractor:承包商汇报内容
    /// </summary>
    [Serializable]
    public partial class ContractorReport
    {
        public ContractorReport()
        {

        }
        #region Model
        private int _id;
        private string _IsReport;
        private int _DailyManagementID;
        private float _GroupID;
        private int _ClassID;
        private int _ContractorID;
        private DateTime _AddDate;
        private string _WorkContent;
        private string _RiskContent;
        private string _ControlContent;
        private int _optsNums;
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 承包商是否汇报
        /// </summary>
        public string IsReport
        {
            set { _IsReport = value; }
            get { return _IsReport; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public int DailyManagementID
        {
            set { _DailyManagementID = value; }
            get { return _DailyManagementID; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public float GroupID
        {
            set { _GroupID = value; }
            get { return _GroupID; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public int ClassID
        {
            set { _ClassID = value; }
            get { return _ClassID; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public int ContractorID
        {
            set { _ContractorID = value; }
            get { return _ContractorID; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public DateTime AddDate
        {
            set { _AddDate = value; }
            get { return _AddDate; }
        }
        /// <summary>
        /// 品牌产地
        /// </summary>
        public string WorkContent
        {
            set { _WorkContent = value; }
            get { return _WorkContent; }
        }
        /// <summary>
        /// 设备故障具体描述
        /// </summary>
        public string RiskContent
        {
            set { _RiskContent = value; }
            get { return _RiskContent; }
        }
        /// <summary>
        /// 报修人
        /// </summary>
        public string ControlContent
        {
            set { _ControlContent = value; }
            get { return _ControlContent; }
        }
        public int optsNums
        {
            set { _optsNums = value; }
            get { return _optsNums; }
        }
        #endregion Model
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// 
    /// </summary>
    public partial class ContractorReport
    {
        private readonly Catering_Operation.ContractorReport dal = new Catering_Operation.ContractorReport();
        public ContractorReport()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.ContractorReport model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.ContractorReport model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string strwhere)
        {

            return dal.Delete(strwhere);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContractorReport GetModel(int Id)
        {
            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContractorReport> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContractorReport> DataTableToList(DataTable dt)
        {
            List<Catering_Model.ContractorReport> modelList = new List<Catering_Model.ContractorReport>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.ContractorReport model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class ContractorReport
    {
        public ContractorReport()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.ContractorReport model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DailyContra(");
            strSql.Append("DailyManagementID,GroupID,ClassID,ContractorID,AddDate,WorkContent,RiskContent,ControlContent,optsNums)");
            strSql.Append(" values (");
            strSql.Append("@DailyManagementID,@GroupID,@ClassID,@ContractorID,@AddDate,@WorkContent,@RiskContent,@ControlContent,@optsNums)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@DailyManagementID", SqlDbType.Int,-1),
                    new SqlParameter("@GroupID", SqlDbType.Int,-1),
                    new SqlParameter("@ClassID", SqlDbType.Int,-1),
					new SqlParameter("@ContractorID", SqlDbType.Int,-1),
					new SqlParameter("@AddDate", SqlDbType.Date,-1),
					new SqlParameter("@WorkContent", SqlDbType.Text,-1),
                    new SqlParameter("@RiskContent", SqlDbType.Text,-1),
                    new SqlParameter("@ControlContent", SqlDbType.Text,-1),                    
					new SqlParameter("@optsNums", SqlDbType.Int,-1)};
            parameters[0].Value = model.DailyManagementID;
            parameters[1].Value = model.GroupID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.ContractorID;
            parameters[4].Value = model.AddDate;
            parameters[5].Value = model.WorkContent;
            parameters[6].Value = model.RiskContent;
            parameters[7].Value = model.ControlContent;
            parameters[8].Value = model.optsNums;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.ContractorReport model)
        {
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("update Moon set ");
            //strSql.Append("MoonName=@MoonName,");
            //strSql.Append("ClassId=@ClassId,");
            //strSql.Append("Remark=@Remark");
            //strSql.Append(" where Id=@Id");
            //SqlParameter[] parameters = {
            //        new SqlParameter("@MoonName", SqlDbType.NVarChar,-1),
            //        new SqlParameter("@ClassId", SqlDbType.Int,4),
            //        new SqlParameter("@Remark", SqlDbType.NVarChar,-1),
            //        new SqlParameter("@Id", SqlDbType.Int,4)};
            //parameters[0].Value = model.MoonName;
            //parameters[1].Value = model.ClassId;
            //parameters[2].Value = model.Remark;
            //parameters[3].Value = model.Id;

            //int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            //if (rows > 0)
            //{
            return true;
            //}
            //else
            //{
            //    return false;
            //}
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string strWhere)
        {
            string sql = "delete from DailyContra where " + strWhere;
            int rows = DbHelperSQL.ExecuteSql(sql);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContractorReport GetModel(int Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,MoonName,ClassId,Remark from Moon ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            Catering_Model.ContractorReport model = new Catering_Model.ContractorReport();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContractorReport DataRowToModel(DataRow row)
        {
            Catering_Model.ContractorReport model = new Catering_Model.ContractorReport();

                if (row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["DailyManagementID"].ToString() != "")
                {
                    model.DailyManagementID = int.Parse(row["DailyManagementID"].ToString());
                }
                if (row["GroupID"] != null&&row["GroupID"].ToString()!="")
                {
                    model.GroupID = float.Parse(row["GroupID"].ToString());
                }
                if (row["ClassID"] != null && row["ClassID"].ToString() != "")
                {
                    model.ClassID = int.Parse(row["ClassID"].ToString());
                }
                if (row["ContractorID"].ToString() != "")
                {
                    model.ContractorID = int.Parse(row["ContractorID"].ToString());
                }
                if (row["AddDate"].ToString() != "")
                {
                    model.AddDate = DateTime.Parse(row["AddDate"].ToString());
                }
                if (row["WorkContent"] != null)
                {
                    model.WorkContent = row["WorkContent"].ToString();
                }
                if (row["RiskContent"] != null)
                {
                    model.RiskContent = row["RiskContent"].ToString();
                }
                if (row["ControlContent"] != null)
                {
                    model.ControlContent = row["ControlContent"].ToString();
                }
                if (row["optsNums"].ToString() != "")
                {
                    model.optsNums = int.Parse(row["optsNums"].ToString());
                }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM DailyContra ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}


